﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace NakovBlog
{
    public class BlogService : IBlogService
    {
        public List<BlogDTO> GetBlogs() 
        {
            BlogDatabaseEntities context = new BlogDatabaseEntities();
            List<BlogDTO> shit = new List<BlogDTO>();
            foreach (var blog in context.Blogs) 
            {
                shit.Add(BlogDTO.ConvertFromBlog(blog));
            }
            return shit;
        }

        public BlogDTO GetSingleblog(ComentsContractor contractor)
        {
            BlogDatabaseEntities context = new BlogDatabaseEntities();
            foreach (Blog blog in context.Blogs) 
            {
                if (blog.BlogId == contractor.blogId) 
                {
                    return BlogDTO.ConvertFromBlog(blog);
                }
            }
            throw new Exception("no such blog");
        }

        public void AddComent(ComentDTO coment)
        {
            BlogDatabaseEntities context = new BlogDatabaseEntities();
            context.Coments.AddObject(coment.ToComent());
            context.SaveChanges();
        }
    }
}
